<template>
  <view>
    <biaotou title="现场人员信息"></biaotou>
    <inputForm v-model="form" ref="form" :list="list">
    </inputForm>
  </view>
</template>

<script>
import {sexTypeJson} from "../mock/mockJson";
import Biaotou from "./biaotou.vue";
import luchangtianjia from "./luchantianjia.vue";
import inputForm from "@/components/inputForm.vue";
import {selectDicByCode} from "../../../api/lupeiwenshu";
import {getAgeByIdCard} from "@/utils/fun";

export default {
  components: {luchangtianjia, Biaotou, inputForm},
  data() {
    return {
      clientJobSelectShow: false,
      form: {
        sceneName: '',
        sceneGender: '1',
        sceneIdcard: '身份证',
        sceneIdcardNum: '',
        sceneAge: '',
        sceneJob: '司机',
        sceneTel: '',
        sceneAddr: '',
        sceneCompany: '',
        sceneRelation:''
      },
      list: [
        {
          label: '姓名：',
          prop: 'sceneName',
        },
        {
          label: '性别：',
          prop: 'sceneGender',
          type: 'select',
          dicData: sexTypeJson,
        },
        {
          label: '证件类型：',
          prop: 'sceneIdcard',
          type: 'select',
          props: {
            label: 'name',
            value: 'name'
          },
          dicData: []
        },
        {
          label: '证件号：',
          prop: 'sceneIdcardNum',
        },
        {
          label: '年龄：',
          prop: 'sceneAge',
        },
        {
          label: "职业：",
          prop: 'sceneJob',
          type: 'select',
          props: {
            label: 'name',
            value: 'name'
          },
          dicData: []
        },
        {
          label: '电话：',
          prop: 'sceneTel',
        }, {
          label: '住址：',
          prop: 'sceneAddr',
          type: 'textarea',
        }, {
          label: '单位：',
          prop: 'sceneCompany',
        }, {
          label: '与案件关系：',
          prop: 'sceneRelation',
          labelWidth: 260
        }
      ],
    };
  },
  watch: {
    'form.sceneIdcardNum'(val) {
      if(this.form.sceneIdcard === '身份证'){
        try {
          this.form.sceneAge = getAgeByIdCard(val)
        }catch{}
      }
    },
  },
  methods: {
    async initSelectJson() {
      this.list.find(item => item.label === '证件类型：').dicData = (await selectDicByCode('zjlx')).data;
      this.list.find(item => item.label === '职业：').dicData = (await selectDicByCode('job')).data;
    },
  },
  // 必须要在onReady生命周期，因为onLoad生命周期组件可能尚未创建完毕
  mounted() {
    this.initSelectJson()

    // this.getUserList();

    uni.getStorage({
      key: 'userInfo',
      success: (res) => {
        if (res.data) {
          this.form.fillPerson = res.data.realName
        }
      }
    });
  },

};
</script>
